package com.sunnada.btfvilg.controller;

import com.sunnada.btfvilg.common.response.Result;
import com.sunnada.btfvilg.common.response.ResultFactory;
import com.sunnada.btfvilg.entity.User;
import com.sunnada.btfvilg.model.request.UserParamVo;
import com.sunnada.btfvilg.model.request.UserRegParamVo;
import com.sunnada.btfvilg.model.response.UserListVo;
import com.sunnada.btfvilg.model.response.UserVo;
import com.sunnada.btfvilg.model.response.WordVo;
import com.sunnada.btfvilg.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户相关的接口
 */
@RestController
@RequestMapping("user")
@Api(tags = "用户")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/delUser")
    @ApiOperation(value = "删除用户", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", dataType = "String", paramType = "query", required = true)
    })
    public Result<Object> delUser(String uid) {
        userService.delUser(uid);
        return ResultFactory.success("删除成功", null);
    }


    @PostMapping("/updateUser")
    @ApiOperation(value = "修改用户信息", httpMethod = "POST")
    public Result<Object> updateUser(@Validated @RequestBody UserRegParamVo userRge) {
        userService.updateUser(userRge);
        return ResultFactory.success("修改成功",null);
    }

    @GetMapping("/getUserList")
    @ApiOperation(value = "获取用户列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "String", paramType = "query", required = true),
            @ApiImplicitParam(name = "numPerPage", value = "每页记录数", dataType = "String", paramType = "query", required = true)
    })
    public Result<UserListVo> getUserList(Integer page, Integer numPerPage) {
        UserListVo userList = userService.getUserList(page, numPerPage);
        return ResultFactory.success(userList);
    }

    @GetMapping("/getUserById")
    @ApiOperation(value = "通过用户id获取用户信息", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uid", value = "用户id", dataType = "String", paramType = "query", required = true)
    })
    public Result<User> getUserById(String uid) {
        User user = userService.getUserById(uid);
        return ResultFactory.success(user);
    }

}
